package com.ruoyi.hk.mapper.message;

import com.ruoyi.hk.domain.DocMsg;
import com.ruoyi.hk.domain.User;
import com.ruoyi.hk.domain.vo.DocMessageVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DocMessageMapper {
    Integer save(DocMsg message);

    List<DocMsg> getChatHistory(@Param("userId") Long userId, @Param("targetId") Long targetId);

    @Select("select * from doc_msg where msg_id = #{lastMessageId}")
    DocMsg selectById(Long lastMessageId);

    DocMsg selectLastMessageBetweenUsers(Map<String, Object> messageParams);

    void updateMsg(Map<String, Object> params);

    @Select("select count(*) from doc_msg where receiver_id = #{receiverId} and sender_id = #{senderId} and is_read = 0")
    Integer count(Map<String, Object> params);

    /**
     * 根据用户ID查询用户信息（包含团队ID）
     */
    User selectUserWithTeamById(Long userId);

    /**
     * 查询所有管理员用户
     */
    List<User> selectAdminUsers();

    /**
     * 根据团队ID查询该团队下的所有医生
     */
    List<User> selectDoctorsByTeamId(Long teamId);

    /**
     * 根据家庭ID查询该家庭下的所有用户
     */
    List<User> selectUsersByFamilyId(Long familyId);

    /**
     * 根据团队ID查询签约该团队的所有家庭ID
     */
    List<Long> selectFamilyIdsByTeamId(Long teamId);

    /**
     * 根据用户ID查询该用户是否加入家庭
     */
    Long selectFamilyIdByUserId(Long userId);

    /**
     * 根据用户ID查询该用户所在家庭的团队ID
     */
    Long selectTeamIdByUserId(Long userId);
}
